package com.water.camera.view.temp;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.water.camera.R;
import com.water.camera.bean.EditItem;
import com.water.camera.databinding.IncludeTemplateThreeBinding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Temp3View extends BaseTemp {

    IncludeTemplateThreeBinding binding;

    public Temp3View(@NonNull Context context) {
        super(context);
    }

    public Temp3View(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Temp3View(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        super.init(type);
        binding = IncludeTemplateThreeBinding.inflate(LayoutInflater.from(getContext()), this, true);
        binding.wordRv.setLayoutManager(new LinearLayoutManager(getContext()));
        update();
    }

    @Override
    public void update() {
        setText(binding.tvLog, "title_temp3", binding.tvLog);
        setText(binding.tvWeatherValue, "weather_temp3", binding.llWeather);
        setText(binding.tvProgress, "progress_temp3", binding.llProgress);
        setText(binding.headReportTimeTv, "date_temp3", binding.llDate);
        setTime(binding.headReportTimeTv, new SimpleDateFormat("yyyy/MM/dd"));

        setText(binding.tvBeizhu, "beizhu_temp3", binding.llBeizhu);
        setText(binding.tvRecord, "record_temp3", binding.llRecored);

        int color = getColor();
        binding.rlBackground.setBackgroundColor(color);

        super.update();
    }

    @Override
    protected String getTimeKey() {
        return "date_temp3";
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title_temp3", "标题"));
        list.add(new EditItem("date_temp3", "日期", true));
        list.add(new EditItem("weather_temp3", "天气"));
        list.add(new EditItem("progress_temp3", "进度"));
        list.add(new EditItem("beizhu_temp3", "备注"));
        list.add(new EditItem("record_temp3", "记录人"));

        ArrayList tmp = super.getEditItems();
        tmp.addAll(0, list);
        tmp.add(new EditItem("custom1", "添加自定义选项"));

        return tmp;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.headReportTimeTv, new SimpleDateFormat("yyyy/MM/dd"));
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    protected int getDefaultColor() {
        return 0xff72A0EB;
    }

    @Override
    protected RecyclerView getCustomRecyclerView() {
        return binding.wordRv;
    }

    @Override
    protected int getTemplateItemLayout() {
        return R.layout.item_template3;
    }
}
